package org.windowkit.toolkit.widget.tree;

import java.io.File;

import javax.swing.tree.DefaultMutableTreeNode;

public class FileNode extends DefaultMutableTreeNode{
    /**
	 *
	 */
	private static final long serialVersionUID = -634628408824983192L;
	public FileNode(final File f){
        super(f);
        if(f != null){
            if(f.isDirectory()){
                setAllowsChildren(true);
            }else{
                setAllowsChildren(false);
            }
        }
    }
    @Override
    public File getUserObject() {
        return (File)super.getUserObject();
    }
    @Override
    public String toString() {
        if (userObject == null) {
            return null;
        }
        if(userObject instanceof File){
            File uObj = (File)userObject;
            String name = uObj.getName();
            int index = name.indexOf(".java");
            if(index != -1){
                name = name.substring(0, index);
            }
            return name;
        }
        return userObject.toString();
    }
}
